<?php declare(strict_types=1);
/**
 * @author      xianganyall <xianganyall@gmail.com>
 * @copyright   2023-2025 owner
 **/

namespace Srv\Conf\ConfModel;

use Srv\Libs\Frame\Conf;

final class PayAlipayConfGroup
{
    private array $PayAlipayConfGroupNameList       = [];       // PayAlipayConf List groupName

    /**
     * @return array
     * getGroupNameList
     */
    public function getGroupNameList():array
    {
        $PayAlipayConfList          = [];
        $groupNameList              = Conf::getGroupNameList(PayAlipayConf::PREFIX);
        if(count($groupNameList) < 1) return $PayAlipayConfList;
        foreach ($groupNameList as $groupName){
            $PayAlipayConf          = $this->getByGroupName($groupName);
            if($PayAlipayConf instanceof PayAlipayConf) $PayAlipayConfList[$groupName] = $PayAlipayConf;
        }
        return $PayAlipayConfList;
    }

    /**
     * @param string $groupName
     * @return PayAlipayConf|null
     * getByGroupName
     */
    public function getByGroupName(string $groupName):?PayAlipayConf
    {
        if(strlen($groupName) < 1) return null;
        if(isset($this->PayAlipayConfGroupNameList[$groupName]) && $this->PayAlipayConfGroupNameList[$groupName] instanceof PayAlipayConf) return $this->PayAlipayConfGroupNameList[$groupName];
        $confData                                       = Conf::getGroupList(PayAlipayConf::PREFIX.$groupName.'.', false, true);
        if(count($confData) < 1) return null;
        $this->PayAlipayConfGroupNameList[$groupName]     = new PayAlipayConf($confData, $groupName);
        return $this->PayAlipayConfGroupNameList[$groupName];
    }
}